using System;
using Sirenix.OdinInspector;
using UnityEngine;
using UnityEngine.EventSystems;

namespace Demo2
{
    public class NetWithMonoInitialLife : FatherMono,
        IPointerClickHandler,
        IPointerEnterHandler,
        IPointerExitHandler,
        IDisposable
    {
        private int updateFrameCount = 0;
        private int fixedFrameCount = 0; // 100
        private int lateUpdateFrameCount = 0;
        private int m_TestValue = 0;

        public int TestValue
        {
            get { return m_TestValue; }
            set { m_TestValue = value; }
        }

        /// <summary>
        /// 是否启用Update生命周期
        /// </summary>
        public bool IsEnableUpdate = false;

        public NetWithMonoInitialLife()
        {
            Debug.Log("NetWithMonoInitialLife()->无参构造函数初始化");
        }

        public NetWithMonoInitialLife(int a)
        {
            Debug.Log("NetWithMonoInitialLife()->有参构造函数初始化");
        }

        private void Awake()
        {
            Debug.Log("=====Awake======");
        }

        private void OnEnable()
        {
            Debug.Log("=====OnEnable======");
        }

        public void Reset()
        {
            Debug.Log("======Reset======");
        }

        public void Start()
        {
            Debug.Log("=====Start======");
        }

        public void Update()
        {
            if (!IsEnableUpdate)
                return;

            Debug.Log($"=====Update:{Time.frameCount}======");
        }

        public void FixedUpdate()
        {
            if (!IsEnableUpdate)
                return;
            fixedFrameCount++;
            Debug.Log($"=====FixedUpdate:{fixedFrameCount}======");
        }

        public void LateUpdate()
        {
            if (!IsEnableUpdate)
                return;
            Debug.Log($"=====LateUpdate:{Time.frameCount}======");
        }

        private void OnDisable()
        {
            Debug.Log("=====OnDisable======");
        }

        public void Dispose()
        {
            Debug.Log("======Dispose======");
        }

        public void OnDestroy()
        {
            Debug.Log("======OnDestroy======");
        }

        #region Application 生命周期

        private void OnApplicationFocus(bool hasFocus)
        {
            Debug.Log("NetWithMonoInitialLife()->OnApplicationFocus(hasFocus)");
        }

        private void OnApplicationPause(bool pauseStatus)
        {
            Debug.Log("NetWithMonoInitialLife()->OnApplicationPause(pauseStatus)");
        }

        private void OnApplicationQuit()
        {
            Debug.Log("NetWithMonoInitialLife()->OnApplicationQuit()");
        }

        #endregion

        #region IPointer 生命周期

        public void OnPointerClick(PointerEventData eventData)
        {
            PauseApplication();
            Debug.Log($"<color=red>点击到UI:{Time.frameCount}</color>");
        }

        public void OnPointerEnter(PointerEventData eventData)
        {
            PauseApplication();
            Debug.Log($"<color=red>进入到UI范围:{Time.frameCount}</color>");
        }

        public void OnPointerExit(PointerEventData eventData)
        {
            PauseApplication();
            Debug.Log($"<color=red>退出UI范围:{Time.frameCount}</color>");
        }

        #endregion

        #region 测试方法

        [Button("暂停游戏")]
        public void PauseApplication()
        {
            // EditorApplication.isPaused = true;
        }

        [Button("恢复游戏")]
        public void ResetApplication()
        {
            // EditorApplication.isPaused = false;
        }

        [Button("0.5倍速")]
        public void HalfTimeScale()
        {
            Time.timeScale = 0.5f;
        }
        #endregion
    }
}
